package com.example.demo.swj.uitl;

public class NeuqEncrypt {


    /**
     *   加密
     * 
     * @param content
     * @param encryptType
     * @param encryptKey
     * @param charset
     * @return
     * @throws NeuqApiException
     */
    public static String encryptContent(String content, String encryptType, String encryptKey,
                                        String charset) throws NeuqApiException {
        if (NeuqConstants.EncryptType.AES.equals(encryptType)) {
            return EncryptUtil.aesEncrypt(encryptKey, content , charset);
        } else if (NeuqConstants.EncryptType.SM4.equals(encryptType)) {
            return EncryptUtil.sm4Encrypt(encryptKey, content , charset);
        } else if (NeuqConstants.EncryptType.NONE.equals(encryptType)) {
            return content;
        } else {
            throw new NeuqApiException("当前不支持该算法类型：encrypeType=" + encryptType);
        }
    }

    /**
     *  解密
     * 
     * @param content
     * @param encryptType
     * @param encryptKey
     * @param charset
     * @return
     * @throws NeuqApiException
     */
    public static String decryptContent(String content, String encryptType, String encryptKey,
                                        String charset) throws NeuqApiException {
        if (NeuqConstants.EncryptType.AES.equals(encryptType)) {
            return EncryptUtil.aesDecrypt(encryptKey,content, charset);
        } else if (NeuqConstants.EncryptType.SM4.equals(encryptType)) {
            return EncryptUtil.sm4Decrypt(encryptKey, content, charset);
        } else if (NeuqConstants.EncryptType.NONE.equals(encryptType)) {
            return content;
        } else {
            throw new NeuqApiException("当前不支持该算法类型：encrypeType=" + encryptType);
        }

    }


}
